package com.atguigu.eduorder.service.impl;

import com.atguigu.eduorder.client.EduClient;
import com.atguigu.eduorder.client.UcenterClient;
import com.atguigu.eduorder.entity.Order;
import com.atguigu.eduorder.mapper.OrderMapper;
import com.atguigu.eduorder.service.OrderService;
import com.atguigu.eduorder.utils.OrderNoUtil;
import com.atguigu.servicebase.vo.EduCourseVo;
import com.atguigu.servicebase.vo.UcenterMemberVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author ryan
 * @since 2021-10-30
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private EduClient eduClient;

    @Autowired
    private UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberId) {
        //id获取用户信息
        EduCourseVo courseInfo = eduClient.getCourseInfoByIdOrder(courseId);
        //id获取课程信息
        UcenterMemberVo memberInfo = ucenterClient.getMemberInfoById(memberId);
        Order order = new Order();
        order.setMobile(memberInfo.getMobile());
        order.setNickname(memberInfo.getNickname());
        order.setMemberId(memberId);
        order.setCourseCover(courseInfo.getCover());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setStatus(0);//支付状态：（ 0：尚未支付，1：已经支付 ）
        order.setPayType(1);//支付类型： 1：微信 ， 2：支付宝
        order.setOrderNo(OrderNoUtil.getOrderNo()); //订单号
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
